package com.example.stretching;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;


	/**
	 * DB 내용을 client로 연결시키는 adapter
	 * @author DS
	 *
	 */

public class AlarmAdapter extends BaseAdapter {
	Button	btnRemove; 
	Context mContext;
//	ArrayList<String> mData;
	LayoutInflater inflater;
	static ArrayList<AlarmData> arrayListAlarmDatas;
	static AlarmManager alarmManager;
	static ArrayList<String> arrayWeek;
	public static int mHour, mHour2;
	public static int mMinute, mMinute2;
	public static String mMon, mTue, mWed, mThu, mFri, mSat, mSun;
	public static String onoff, complete;
	public static final int j = (mHour2 - mHour);
	
	static TextView textView4, textViewList;
	protected int position;
	protected ViewHolder viewHolder;
	static AlarmAdapter arrayAdapterAlarmList;

//	static protected AlarmAdapter mAdapter;


	
	public AlarmAdapter(Context context, ArrayList<AlarmData> array) {
		
		inflater = LayoutInflater.from(context);
		arrayListAlarmDatas = array;
	
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayListAlarmDatas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
//	public boolean removeData(int position){
//		arrayListAlarmDatas.remove(position);
//		notifyDataSetChanged();
//		return false;
//	}


	/**
	 * viewHolder에 알람리스트에 들어갈 내용들을 넣어서 layout inflate를 통해
	 *list레이아웃에 넣어준다. list레이아웃은 include_list에 포함되어서
	 *두번째 탭 내용으로 들어가게 된다. 두번째 탭의 하위레이아웃으로 들어가기 때문에 include_list 사용하고
	 *두번째 탭인 real_main.xml에서 list를 include한다.
	 *viewHolder에서 알람데이터의 리스트인 arrayListAlarmDatas 의 값을 받아서 뿌려준다.
	 *
	 */
	public View getView(final int position, View convertview, ViewGroup parent) {
//		View layout = inflater.inflate(R.layout.activity_main, this);
//		textViewList = (TextView)layout.findViewById(R.id.textViewList);
		
		
		
		View v = convertview;
		if(v== null){
			viewHolder = new ViewHolder();
			v = inflater.inflate(R.layout.list, null);
			
	        viewHolder.mon = (TextView) v.findViewById(R.id.mon_View);
	        viewHolder.tue = (TextView) v.findViewById(R.id.tue_View);
	        viewHolder.wed = (TextView) v.findViewById(R.id.wed_View);
	        viewHolder.thu = (TextView) v.findViewById(R.id.thu_View);
	        viewHolder.fri = (TextView) v.findViewById(R.id.fri_View);
	        viewHolder.sat = (TextView) v.findViewById(R.id.sat_View);
	        viewHolder.sun = (TextView) v.findViewById(R.id.sun_View);
	        viewHolder.timeText4 = (TextView) v.findViewById(R.id.timeText4);
			viewHolder.onoff = (TextView)v.findViewById(R.id.on_off_View);
			v.setTag(viewHolder);
			
		}else {
			viewHolder = (ViewHolder)v.getTag();
		}
		
		viewHolder.mon.setText(arrayListAlarmDatas.get(position).mon);
		viewHolder.tue.setText(arrayListAlarmDatas.get(position).tue);
		viewHolder.wed.setText(arrayListAlarmDatas.get(position).wed);
		viewHolder.thu.setText(arrayListAlarmDatas.get(position).thu);
		viewHolder.fri.setText(arrayListAlarmDatas.get(position).fri);
		viewHolder.sat.setText(arrayListAlarmDatas.get(position).sat);
		viewHolder.sun.setText(arrayListAlarmDatas.get(position).sun);
		viewHolder.timeText4.setText(arrayListAlarmDatas.get(position).hh + ":"+
				arrayListAlarmDatas.get(position).mm + " ~ " + 
				arrayListAlarmDatas.get(position).hh2 + ":" +
				arrayListAlarmDatas.get(position).mm2);
//		viewHolder.onoff.setText(arrayListAlarmDatas.get(position).onoff);
		return v;
	}
	
	
	public void setArrayList(ArrayList<AlarmData> arrays){
		AlarmAdapter.arrayListAlarmDatas = arrays;

	}
	
	//DB에 있는 데이터를 불러온다.
	public ArrayList<AlarmData> getArrayList(){
		return arrayListAlarmDatas;
	}

	static class ViewHolder{
		TextView mon;
		TextView tue;
		TextView wed;
		TextView thu;
		TextView fri;
		TextView sat;
		TextView sun;

		TextView timeText4;
		TextView onoff;
	}
		
	}

